<?php
defined('LMO') or die('Can\'t access !'); 

class LCIndex 
{
    static $instance;
    
    public static function getInstance()
    {
        if(!isset(self::$instance)) {
            self::$instance = new LCIndex();
        }
        
        return self::$instance;
    }
    
    public function checkPermission()
    {
        if(!isset($_SESSION['logged'])) {
            header('location: '.BASE_URL.BS.'index.php?c=user&m=login');
        }
    }
    
    public function indexAction()
    {
        $this->checkPermission();
        $account = LAccount::getInstance();
        $list = LFile::getListFile(SERVER_STORAGE_PATH, SERVER_FILE_EXT);
        $data = array();
        $ipList = array();
        foreach($list as $ip) {
            $ip = str_replace('.conf', '', $ip);
            if($account->checkExist($ip)) {
                $ipList[] = $ip;
            }
        }
        
        if(!empty($ipList)) {
            $monitor = LMonitor::getInstance();
            foreach($ipList as $ip) {
                $log = $monitor->loadLog($ip, LOG_STATUS, true);
                if(!empty($log)) {
                    $server = $account->loadAccount($ip);
                    $server['service'] = $log;
                    $data[] = $server;
                }
            }
        }
        
        $layout = LLayout::getInstance();
        $html = $layout->assign('monitor_list', array('data' => $data));
        $layout->loadLayout($html);
    }
    
}
?>
